# Maintainer: Thore Bödecker <foxxx0@archlinux.org>
# Contributor: Florian Pritz <bluewind@xinu.at>
# Contributor: Karol Babioch <karol@babioch.de>

pkgname=amavisd-milter
pkgver=1.7.2
pkgrel=1
pkgdesc="sendmail milter for amavisd-new using the AM.PDP protocol"
arch=('loong64' 'x86_64')
url="http://amavisd-milter.sourceforge.net/"
license=('BSD')
depends=('amavisd-new')
makedepends=('libmilter')
source=("https://github.com/prehor/amavisd-milter/releases/download/$pkgver/amavisd-milter-$pkgver.tar.gz"
        'amavisd-milter.service')
sha512sums=('639a5a4f92131f9b8d004255819e36dedd529ec95f8290663c6ea5860dbbce049a822ba0e68158228716778265009b93024e9102defdf9250d4e889157008181'
            '0a07da1f1c1299ac26fc8ccd77919e4c5c69ea3e673c1d34f46f730899e2b4234784147fb9929e635a6dc7a40474ca0ba2f03785125ba5b37b1252eb986b4510')

prepare() {
    cd "${srcdir}/${pkgname}-${pkgver}"

    # change upstream default paths (must match those of amavisd-new)
    sed -i 's|/var/amavis|/var/spool/amavis|g' "${pkgname}/amavisd-milter.8"
}

build() {
    cd "${srcdir}/${pkgname}-${pkgver}"
    ./configure \
        --prefix=/usr \
        --bindir=/usr/bin \
        --sbindir=/usr/bin \
        --sysconfdir=/etc/amavis \
        --localstatedir=/var/spool/amavis \
        --sharedstatedir=/usr/share
    make
}

check() {
    cd "${srcdir}/${pkgname}-${pkgver}"
    make check
}

package() {
    cd "${srcdir}/${pkgname}-${pkgver}"
    make DESTDIR="${pkgdir}" install
    # license
    install -D -m644 "${srcdir}/${pkgname}-${pkgver}/LICENSE" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
    # systemd unit
    install -D -m644 "${srcdir}/amavisd-milter.service" "${pkgdir}/usr/lib/systemd/system/amavisd-milter.service"
}
